package com.piggy.sys.controller;

import com.piggy.common.core.utils.sms.SmsConfig;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.satoken.annotation.Inner;
import com.piggy.common.core.domain.R;
import com.piggy.sys.api.bo.SmsNotify;
import com.piggy.sys.api.bo.SysEmailBo;
import com.piggy.sys.api.bo.SysSmsBo;
import com.piggy.sys.api.bo.SysSmsQueryBo;
import com.piggy.sys.api.vo.SysSmsVo;
import com.piggy.sys.service.ISysSmsService;
import io.swagger.annotations.ApiOperation;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/sysSms")
public class SysSmsController extends BaseController {

    @Resource
    private ISysSmsService iSysSmsService;

    /**
     * 获取注册用户手机验证码
     *
     * @return
     */
    @Inner
    @GetMapping("/userRegSendSms/{phone}")
    public R<Boolean> userRegSendSms(@PathVariable("phone") String phone) {
        return R.ok(iSysSmsService.userRegSendSms(phone));
    }

    /**
     *
     *
     * @return
     */
    @Inner
    @GetMapping("/createAccount/{phone}")
    public R<Boolean> createAccount(@PathVariable("phone") String phone, @RequestParam("passwd")String passwd, @RequestParam("company") String company, @RequestParam("regTime") String regTime) {
        return R.ok(iSysSmsService.createAccount(phone, passwd, company, regTime));
    }

    /**
     *
     *
     * @return
     */
    @Inner
    @GetMapping("/resetPasswd/{phone}")
    public R<Boolean> resetPasswd(@PathVariable("phone") String phone, @RequestParam("password") String password, @RequestParam("company") String company) {
        return R.ok(iSysSmsService.resetPasswd(phone, password, company));
    }

    /**
     *
     *
     * @return
     */
    @Inner
    @GetMapping("/waybillNotify/{phone}")
    public R<Boolean> waybillNotify(@PathVariable("phone") String phone, @RequestParam("waybillNo") String waybillNo, @RequestParam("status") String status, @RequestParam("nextStatus") String nextStatus) {
        return R.ok(iSysSmsService.waybillNotify(phone, waybillNo, status, nextStatus));
    }

    /**
     *
     *
     * @return
     */
    @Inner
    @GetMapping("/scheduleNotify/{phone}")
    public R<Boolean> scheduleNotify(@PathVariable("phone") String phone, @RequestParam("scheduleNo") String scheduleNo, @RequestParam("status") String status, @RequestParam("nextStatus") String nextStatus) {
        return R.ok(iSysSmsService.scheduleNotify(phone, scheduleNo, status, nextStatus));
    }

    /**
     *
     *
     * @return
     */
    @Inner
    @PostMapping("/smsNotify/{phone}")
    public R<Boolean> smsNotify(@PathVariable("phone") String phone, @RequestBody SmsNotify smsNotify) {
        return R.ok(iSysSmsService.smsNotify(phone, smsNotify));
    }

    /**
     * 获取注册用户手机验证码
     *
     * @return
     */
    @Inner
    @GetMapping("/getConfig")
    public R<SmsConfig> getConfig() {
        return R.ok(iSysSmsService.getConfig());
    }

    @Inner
    @PostMapping("/sendMail")
    public R<Boolean> sendMail(@RequestBody SysEmailBo bo) {
        return R.ok(iSysSmsService.sendMail(bo.getContent(), bo.getSubject(), bo.getParams(), bo.getReceiver(), bo.getFiles()));
    }

    @Inner
    @PostMapping("/sendSms")
    public R<Boolean> sendSms(@RequestBody SysSmsBo bo) {
        return R.ok(iSysSmsService.sendSms(bo));
    }

    /**
     * 查询消息列表
     */
    @ApiOperation("查询消息列表")
    //@SaCheckPermission("incar:sms:list")
    @PostMapping("/list")
    public TableDataInfo<SysSmsVo> list(@Validated SysSmsQueryBo bo) {
        return iSysSmsService.queryPageList(bo);
    }
}
